package com.ruoyi.zhmk.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkCarinout;
import com.ruoyi.zhmk.service.IZhmkCarinoutService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆进出记录Controller
 * 
 * @author sxl
 * @date 2021-06-15
 */
@Controller
@RequestMapping("/zhmk/carinout")
public class ZhmkCarinoutController extends BaseController
{
    private String prefix = "zhmk/carinout";

    @Autowired
    private IZhmkCarinoutService zhmkCarinoutService;

    @RequiresPermissions("zhmk:carinout:view")
    @GetMapping()
    public String carinout()
    {
        return prefix + "/carinout";
    }

    /**
     * 查询车辆进出记录列表
     */
    @RequiresPermissions("zhmk:carinout:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhmkCarinout zhmkCarinout)
    {
        startPage();
        List<ZhmkCarinout> list = zhmkCarinoutService.selectZhmkCarinoutList(zhmkCarinout);
        return getDataTable(list);
    }

    /**
     * 导出车辆进出记录列表
     */
    @RequiresPermissions("zhmk:carinout:export")
    @Log(title = "车辆进出记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhmkCarinout zhmkCarinout)
    {
        List<ZhmkCarinout> list = zhmkCarinoutService.selectZhmkCarinoutList(zhmkCarinout);
        ExcelUtil<ZhmkCarinout> util = new ExcelUtil<ZhmkCarinout>(ZhmkCarinout.class);
        return util.exportExcel(list, "车辆进出记录数据");
    }

    /**
     * 新增车辆进出记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆进出记录
     */
    @RequiresPermissions("zhmk:carinout:add")
    @Log(title = "车辆进出记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhmkCarinout zhmkCarinout)
    {
        return toAjax(zhmkCarinoutService.insertZhmkCarinout(zhmkCarinout));
    }

    /**
     * 修改车辆进出记录
     */
    @GetMapping("/edit/{cinoutId}")
    public String edit(@PathVariable("cinoutId") Long cinoutId, ModelMap mmap)
    {
        ZhmkCarinout zhmkCarinout = zhmkCarinoutService.selectZhmkCarinoutById(cinoutId);
        mmap.put("zhmkCarinout", zhmkCarinout);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆进出记录
     */
    @RequiresPermissions("zhmk:carinout:edit")
    @Log(title = "车辆进出记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhmkCarinout zhmkCarinout)
    {
        return toAjax(zhmkCarinoutService.updateZhmkCarinout(zhmkCarinout));
    }

    /**
     * 删除车辆进出记录
     */
    @RequiresPermissions("zhmk:carinout:remove")
    @Log(title = "车辆进出记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhmkCarinoutService.deleteZhmkCarinoutByIds(ids));
    }
}
